package br.com.util;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ER 
{
	public synchronized static String buscaExprecao( String strTexto, String strPattern )
	{
		String strRet = "";
		
		Pattern pat = Pattern.compile( strPattern );
		
		Matcher matcher = pat.matcher( strTexto );
		
		if( matcher.find( ) )
			return matcher.group( 1 );
		
		return strRet;
	}
	
	public synchronized static List<String[]> findAll( String strContent, String... strPatterns )
	{
		List<String[]> lstRet = new ArrayList<String[]>( );
		
		Matcher[] matchers = new Matcher[strPatterns.length];
		
		for( int i = 0; i < strPatterns.length; i++ ) 
			matchers[i] = Pattern.compile( strPatterns[i] ).matcher( strContent );
		
		boolean bfind = true;
		
		while( true )
		{
			
			for( int i = 0; i < matchers.length; i++ )
				bfind = matchers[i].find( ) && bfind;
			
			if( !bfind )
				break;
			
			String[] aStr = new String[strPatterns.length];
			
			for( int i = 0; i < matchers.length; i++ )
				aStr[i] = matchers[i].group( 1 );
			
			lstRet.add( aStr );
		}
		
		return lstRet;
	}
}